home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / lang / amigatalk.lha / system / Audio.st < prev    next >
Text File  |  2002-04-18  |  6KB  |  159 lines

  1. " ----------------------------------------------------------------------- "
  2. " Audio Class implements control of the audio.device only, NOT any custom "
  3. " hardware you might have.                                                "
  4. ""
  5. "  WARNING:  You should know what you're doing to the Amiga OS before     "
  6. "            messing with this Class, or any other System Class!          "
  7. ""
  8. "  NOTE(S):  Methods marked 'BOOLEAN' return true on success, false on    "
  9. "            failure. "
  10. " ----------------------------------------------------------------------- "
  11.  
  12. Class Audio :Device ! private1 private2 private3 aChannel !
  13. [
  14.    initialize: portName channels: chBytes flags: flags priority: newPriority 
  15.       
  16.       " newPriority is in the range: -128 to 127.
  17.       *
  18.       * flags pertinent to the user are: 
  19.       *    ADIOF_SYNCCYCLE = 32 & ADIOF_NOWAIT = 64.
  20.       * 
  21.       * chbytes is a ByteArray that is only 4 bytes long.  #[ 3 5 10 12 ] 
  22.       * It is encoded as follows for each byte:
  23.       *
  24.       *    Channel 3 Channel 2 Channel 1 Channel 0 Allocation 
  25.       *      RIGHT     LEFT      LEFT      RIGHT      MASK
  26.       *
  27.       *        0         0         1         1        0x03    Stereo
  28.       *        0         1         0         1        0x05    Stereo
  29.       *        1         0         1         0        0x0A    Stereo
  30.       *        1         1         0         0        0x0C    Stereo
  31.       *
  32.       *        0         0         0         1        0x01    MonAural
  33.       *        0         0         1         0        0x02    MonAural
  34.       *        0         1         0         0        0x04    MonAural
  35.       *        1         0         0         0        0x08    MonAural
  36.       *  
  37.       * UNCOMMON USAGE:
  38.       *
  39.       *        0         0         0         0        0x00    NO CHANNELS
  40.       *        0         1         1         0        0x06    Both Left Ch.
  41.       *        0         1         1         1        0x07    Three Channels
  42.       *        1         0         0         1        0x09    Both Right Ch.
  43.       *        1         0         1         1        0x0B    Three Channels
  44.       *        1         1         0         1        0x0D    Three Channels
  45.       *        1         1         1         0        0x0E    Three Channels
  46.       *        1         1         1         1        0x0F    ALL Channels
  47.       "
  48.       private1 <- <primitive 220 1>.
  49.       private2 <- <primitive 220 3 private1 portName flags newPriority chBytes>.
  50.       
  51.       (self openChannel: chBytes priority: newPriority)
  52.         ifFalse: [self error: 'Could NOT open Audio channel(s)!']
  53. |
  54.    openChannel: chByteArray priority: pri ! rval !     " BOOLEAN "
  55.       rval     <- <primitive 220 21 private1 pri chByteArray>.
  56.  
  57.       aChannel <- self myChannel.
  58.  
  59.       ^ rval
  60. |
  61.    myChannel
  62.       ^ <primitive 220 27 private1>
  63. |
  64.    volume: volumeLevel                                 " BOOLEAN "
  65.       ^ <primitive 220 14 private1 volumeLevel>     
  66. |
  67.    period: newPeriod                                   " BOOLEAN "
  68.       " The frequency of the sound you wish to play is 
  69.       * dependent on the period & the length of the sound
  70.       * data.  The frequency is determined by dividing the
  71.       * VideoClockFreq by the product of the period & data 
  72.       * length.  
  73.       *
  74.       * Example:  f = 3579545 / (256 * period) for NTSC
  75.       *           f = 4436618 / (256 * period) for PAL
  76.       * 
  77.       *           where 256 is the length of the data.
  78.       "      
  79.       ^ <primitive 220 13 private1 newPeriod>     
  80. |
  81.    waitCycle                                           " BOOLEAN " 
  82.       ^ <primitive 220 16 private1 aChannel>
  83. |
  84.    read
  85.       ^ <primitive 220 17 private1 aChannel>
  86. |
  87.    setData: aByteArray
  88.       private3 <- <primitive 220 26 private1 aByteArray>
  89. |
  90.    playAt: volume for: duration                        " BOOLEAN "
  91.       " if the duration is zero, the channel will play 
  92.       * continuously, until you abort it (stop method).
  93.       * the number of cycles is dependent on the duration &
  94.       * the frequency (determined by the period & data length).
  95.       *
  96.       *   Example: numCycles = (frequency * duration) / 1000
  97.       *
  98.       * See the 'period:' method for frequency calculation. 
  99.       "
  100.       ^ <primitive 220 15 private1 volume duration aChannel>
  101. |
  102.    start                                               " BOOLEAN "
  103.       ^ <primitive 220 12 private1>
  104. |
  105.    stop                                                " BOOLEAN "
  106.       ^ <primitive 220 11 private1>
  107. |
  108.    reset                                               " BOOLEAN "
  109.       ^ <primitive 220 10 private1>
  110. |
  111.    changePriority: newPriority                         " BOOLEAN "
  112.       ^ <primitive 220 6 private1 newPriority>
  113. |
  114.    flush                                               " BOOLEAN "
  115.       ^ <primitive 220 9 private1>
  116. |
  117.    clear                                               " BOOLEAN "
  118.       ^ <primitive 220 24 private1>
  119. |
  120.    update                                              " BOOLEAN "
  121.       ^ <primitive 220 25 private1>
  122. |
  123.    finish                                              " BOOLEAN "
  124.       ^ <primitive 220 8 private1>
  125. |
  126.    lock                                                " BOOLEAN "
  127.       ^ <primitive 220 7 private1>
  128. |
  129.    read: audioFileName size: size                      " BOOLEAN "
  130.       ^ <primitive 220 18 private1 audioFileName size>
  131. |
  132.    write: audioFileName size: size                     " BOOLEAN "
  133.       ^ <primitive 220 19 private1 audioFileName size>
  134. |
  135.    freeChannel
  136.       " Tell the system you are done with an Audio Channel: "
  137.       <primitive 220 20 private1 private2 aChannel>
  138. |
  139.    disposeData
  140.       <primitive 220 2 private3>.
  141.  
  142.       private3 <- nil.
  143.  
  144.       ^ nil
  145. |
  146.    dispose
  147.       <primitive 220 0 private1 private2>.
  148.       self disposeData.
  149.       <primitive 220 5 private1>.
  150.  
  151.       private1 <- nil. " One-way ticket to death!! "
  152.       private3 <- nil.
  153.       
  154.       ^ nil
  155. |
  156.    audioKey
  157.       ^ <primitive 220 22 private1> " NOT really needed at this time. "
  158. ]
  159.